import java.util.Arrays;
import java.util.Scanner;

public class test {
    public static void main(String[] args) {
        PersonSortable[] persons;
        Scanner read = new Scanner(System.in);
        int n;
        n = read.nextInt();
        persons = new PersonSortable[n];
        for(int i = 0; i < n; i++)
        {
            String name = read.next();
            int age = read.nextInt();
            persons[i] = new PersonSortable(name,age);
        }
        Arrays.sort(persons);
        for(int i = 0; i < n; i++)
        {
            System.out.println(persons[i]);
        }
    }
}
